#include "A.h"

#define eps 0.0001
#define M 1000

class Fun1 : public Fun
{
public:
	double f(double x)
	{
		return 1/x - tan(x);
	}      
};

double test1()
{
	Fun1 f1;
	Bisection s(f1, 0, PI/2, eps, eps, M);
	return(s.solve());
}

class Fun2 : public Fun
{
public:
	double f(double x)
	{
		return 1/x - pow(2, x);
	}      
};

double test2()
{
	Fun2 f2;
	Bisection s(f2, 0, 1, eps, eps, M);
	return(s.solve());
}

class Fun3 : public Fun
{
public:
	double f(double x)
	{
		return pow(0.5, x) + exp(x) + 2*cos(x) - 6;
	}      
};

double test3()
{
	Fun3 f3;
	Bisection s(f3, 1, 3, eps, eps, M);
	return(s.solve());
}

class Fun4 : public Fun
{
public:
	double f(double x)
	{
		return (pow(x,3)+4*x*x+3*x+5)/(2*pow(x,3)-9*x*x+18*x-2);
	}      
};

double test4()
{
	Fun4 f4;
	Bisection s(f4, 0, 4, eps, eps, M);
	return(s.solve());
}

int main()
{
	printf("The solution of 1/x-tanx is %f\n",test1());
	printf("The solution of 1/x-2^x is %f\n",test2());
	printf("The solution of 2^(-x)+e^x+2cosx-6 is %f\n",test3());
	printf("The solution of (x^3+4x^2+3x+5)/(2x^3-9x^2+18x-2) is %f\n",test4());
}